﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Utility;
using System.Data;
using System.Utility.DBMS;

namespace System.DataProvider
{
    public class IndexBasedDataProvider : IDataProvider
    {

        StoredProc proc = null;
        SqlParameter[] param = null;
        IParamBuilder builder = null;

        static string connection = Settings.GetSettingByKey("DBConnString");
        public IndexBasedDataProvider()
            : this(new DefaultParamBUilder())
        { }

        public IndexBasedDataProvider(IParamBuilder builder)
        {
            StoredProc.CreateList();
            this.builder = builder;
        }


        public int ExcuteQuery(string Query)
        {
            throw new Exception("Method not implement");
        }

        public void ExcuteProc(string procName, object[] dataArray)
        {
            proc = StoredProc.GetProc(procName);
            param = builder.BuildParamSet(proc, dataArray); //BuildParameterSet(proc, dataArray);
            SqlHelper.ExecuteNonQuery(connection, procName, param);
        }

        public DataTable GetDataTable(string procName, object[] dataArray)
        {
            DataSet set = this.GetDataSet(procName, dataArray);
            return set.Tables[0];
        }

        public DataSet GetDataSet(string procName, object[] dataArray)
        {
            proc = StoredProc.GetProc(procName);
            param = builder.BuildParamSet(proc, dataArray); //BuildParameterSet(proc, dataArray);
            return SqlHelper.ExecuteDataset(connection, procName, param);
        }



    }
}
